package io.github.noahzu.daka.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import io.github.noahzu.daka.R
import io.github.noahzu.daka.bean.ConstructionBean
import kotlinx.android.synthetic.main.item_data.view.*

class DataAdapter(val mContext: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
    val mData = ArrayList<Any>()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return DataViewHolder(LayoutInflater.from(mContext).inflate(
            R.layout.item_data,null))
    }

    override fun getItemCount(): Int = mData.size

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        (holder as? DataViewHolder)?.setData(mData[position])
    }


    class DataViewHolder(val rootView : View) : RecyclerView.ViewHolder(rootView) {
        private val mProjNameTv : TextView = rootView.mProjName
        private val mConsUnitTv : TextView = rootView.mConsUnit
        private val mProjLocationTv : TextView = rootView.mProjLocation
        private val mRemarksTv : TextView = rootView.mRemarks
        private val mSponsorTv : TextView = rootView.mSponsor
        private val mTimeTv : TextView = rootView.mTime
        private val mWarningTv : TextView = rootView.mWarning
        private val mPersonInChargeTv : TextView = rootView.mPersonInCharge
        private val mNotesTv : TextView = rootView.mNotes

        fun setData(data : Any?) {
            (data as? ConstructionBean)?.let {
                mProjNameTv.text = "项目名称：" + it.ProjectName
                mConsUnitTv.text = "施工单位：" + it.ConstructionUnit
                mProjLocationTv.text = "项目地址：" + it.Projectlocation
                mRemarksTv.text = "费用约谈：" + it.Remarks
                mSponsorTv.text = "责任人：" + it.Sponsor
                mTimeTv.text = "时间：" + it.Time.toString()
                mWarningTv.text = "违法行为：" + it.VerbalWarning
                mPersonInChargeTv.text = "主办人：" + it.personInCharge
                mNotesTv.text = "备注：" + it.Notes
            }
        }
    }


}